/*
 * @lc app=leetcode.cn id=11 lang=cpp
 *
 * [11] 盛最多水的容器
 */
#include"include.h"
// @lc code=start
class Solution {
public:
    int maxArea(vector<int>& height) {
        // 如果我们移动数字较大的那个指针
        // 那么前者「两个指针指向的数字中较小值」不会增加
        // 后者「指针之间的距离」会减小，那么乘积会减小
        int res = 0;
        int n = height.size();
        if (n<=1){return 0;}

        int left = 0, right = n-1;

        int heightLeft = height[left];
        int heightRight = height[right];

        while(left<right){

            if (height[left]<height[right]){
                int s = height[left] * (right-left);
                if (s > res){res = s;}
                left++;
            } else{
                int s = height[right] * (right-left);
                if (s > res){res = s;}
                right--;
            }

        }

        // int lastLeft = height[0]-1;

        // int rightTop = n-1;

        // for (int i=0;i<n-1;i++){

        //     if (height[i] <= lastLeft){continue;}

        //     int lastRight = height[n-1]-1;
        //     for (int j=rightTop;j>i;j--){

        //         if (height[j] <= lastRight){continue;}

        //         lastRight = height[j];
        //         int m = height[i]<height[j]?height[i]:height[j];
        //         int mm = m*(j-i);
        //         if (mm > res){
        //             res = mm;
        //             rightTop = j;
        //         }
        //     }
        // }
        return res;
    }
};
// @lc code=end

